const path = require('path');
const NODE_ENV = process.env.NODE_ENV;
const dev = path.resolve(__dirname, 'src/env/dev.js');
const prod = path.resolve(__dirname, 'src/env/prod.js');
const envconfig = {
  development: dev,
  production: prod
}
const {
  override,
  fixBabelImports,
  addWebpackPlugin,
  addLessLoader
} = require('customize-cra');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');

const getAlias = () => (config, env) =>{
  let con = { ...config};
  con.resolve.alias = {
    ...con.resolve.alias,
    '@': path.resolve(__dirname, 'src'),
    "env": envconfig[NODE_ENV]
  };
  return con
}

module.exports = override(
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  }),
  addLessLoader({
    javascriptEnabled: true,
  }),
  getAlias(),
  addWebpackPlugin(new AntdDayjsWebpackPlugin())
);